<?php

/**
 * article actions.
 *
 * @package    wills
 * @subpackage article
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ArticleActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
	$this->area = Doctrine::getTable('Area')->findOneBySlug($request->getParameter('area'));//获得当前赛区
    $this->pager = new sfDoctrinePager(
      'Article',
      sfConfig::get('app_per_page_article')
    );
    $this->pager->setQuery(Doctrine::getTable('Article')->createQuery('a'));
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();

    $area = Doctrine::getTable('Area')->findOneBySlug($request->getParameter('area'));
	/* $this->media = $area->getArticleByCategoryQuery('媒体报道')->limit(4)->execute();
    $this->mediaImage = $area->getImageByCategoryQuery('媒体报道')->limit(1)->execute();
    $this->gov   = $area->getArticleByCategoryQuery('政府关注')->limit(4)->execute();
    $this->govImage = $area->getImageByCategoryQuery('政府关注')->limit(1)->execute();
    $this->latest = $area->getArticleByCategoryQuery('最新动态')->limit(8)->execute();
	*/
    $this->latest = $area->getArticleByCategoryQuery('大赛动态')->limit(4)->execute();
    $this->media = $area->getArticleByCategoryQuery('媒体关注')->limit(8)->execute();


    $this->articles = $this->pager->getResults();
  }

    public function executeCategory(sfWebRequest $request)
  {
	$this->area = Doctrine::getTable('Area')->findOneBySlug($request->getParameter('area'));//获得当前赛区
	$this->category =$category= Doctrine::getTable('Category')->findOneById($request->getParameter('catid'));//获得当前类别名称
	$this->catid=$request->getParameter('catid');
	$this->pager = new sfDoctrinePager(
      'Article',
      sfConfig::get('app_per_page_articlecategory')
    );
    $this->pager->setQuery(Doctrine::getTable('Article')
		->createQuery('a')
		->where('a.id IN (select article_id from article_category  where category_id=?)',$request->getParameter('catid'))	
		);
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
    $this->articles = $this->pager->getResults();

    $area = Doctrine::getTable('Area')->findOneBySlug($request->getParameter('area'));

	$this->latest = $area->getArticleByCategoryQuery('大赛动态')->limit(4)->execute();
    $this->media = $area->getArticleByCategoryQuery('媒体关注')->limit(8)->execute();

  }

  public function executeShow(sfWebRequest $request)
  {
	$this->area = Doctrine::getTable('Area')->findOneBySlug($request->getParameter('area'));//获得当前赛区
    $this->article = Doctrine::getTable('Article')->find(array($request->getParameter('id')));
	
	//$articleCategory=$this->articleCategory = Doctrine::getTable('ArticleCategory')
	//	->findOneByArticleId($request->getParameter('id'));
	//$categoryid=$this->categoryid=$articleCategory->getCategoryId();
	//$this->category= Doctrine::getTable('Category')->findOneById($categoryid);//获得当前文章分类
	
    $this->forward404Unless($this->article);
    
    $area = Doctrine::getTable('Area')->findOneBySlug($request->getParameter('area'));
    
    $this->latest = $area->getArticleByCategoryQuery('大赛动态')->limit(4)->execute();
    $this->media = $area->getArticleByCategoryQuery('媒体关注')->limit(8)->execute();

    $this->form = CommentFormFactory::create();
  }

	//查看文章评论
  public function executeShowcomments(sfWebRequest $request)
  {
	$this->articleid=$request->getParameter('articleid');
	$this->article =$article= Doctrine::getTable('article')
       ->find(array($request->getParameter('articleid')));
	
    $this->pager = new sfDoctrinePager(
      'Comment',
      sfConfig::get('app_per_page_articlecomments')
    );

    $this->pager->setQuery($article->getCommentsWithAuthorQuery());
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();

    $this->comments = $this->pager->getResults();
   
	$this->form = CommentFormFactory::create();

  }
} 
